#include "constantes.h"
#include "jeu.h"
#include "editeur.h"

int main(int argc, char *argv[])
{
    SDL_Surface *ecran=NULL, *menu=NULL, *select=NULL, *icone=NULL;
    SDL_Rect pmenu, pselect;
    SDL_Event event;
    int continuer=1;

    pmenu.x=0;
    pmenu.y=0;
    pselect.x=137;
    pselect.y=331;

    SDL_Init(SDL_INIT_VIDEO);
/* ---- Gestion de la petite icone. La transparence ne fonctionne pas... ---- */
    icone=SDL_LoadBMP("GFX/peticone.bmp");
    SDL_SetColorKey(icone, SDL_SRCCOLORKEY, SDL_MapRGB(icone->format, 128, 255, 255));
    SDL_WM_SetIcon(icone,NULL);
/* ---- Initialisation de la fenêtre ---- */
    ecran=SDL_SetVideoMode(TFENETRE,TFENETRE,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Mario Sokoban", NULL);

    menu=IMG_Load("GFX/menu.png");
    select=IMG_Load("GFX/select.png"); // Curseur pour choisir de jouer ou d'éditer un niveau.

    while(continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer=0;
                break;
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    /* --- Gestion du curseur --- */
                    case SDLK_DOWN:
                        if(pselect.y != 331)
                            pselect.y=331;
                        else
                            pselect.y=356;
                        break;
                    case SDLK_UP:
                        if(pselect.y != 356)
                            pselect.y=356;
                        else
                            pselect.y=331;
                        break;
                    case SDLK_RETURN:
                        if(pselect.y == 331)
                            jouer(ecran);
                        else if(pselect.y == 356)
                            editer(ecran);
                        break;
                    case SDLK_SPACE:
                        if(pselect.y == 331)
                            jouer(ecran);
                        else if(pselect.y == 356)
                            editer(ecran);
                        break;
                    case SDLK_ESCAPE:
                        continuer=0;
                        break;
                }
            break;
        }
    SDL_BlitSurface(menu,NULL,ecran,&pmenu);
    SDL_BlitSurface(select,NULL,ecran,&pselect);
    SDL_Flip(ecran);
    }

    SDL_FreeSurface(select);
    SDL_FreeSurface(menu);

    SDL_Quit();
    return EXIT_SUCCESS;
}
